import React from 'react';
import { Button, Popconfirm } from 'antd';
import { formatMessage } from 'umi';

const Index = props => {
  const {
    confirm = false,
    onClick,

    children,
    ...rest
  } = props;

  return confirm ? (
    <Popconfirm title={formatMessage({ id: '是否确认执行' })} {...confirm} onConfirm={onClick}>
      <Button {...rest}>{children}</Button>
    </Popconfirm>
  ) : (
    <Button {...rest} onClick={onClick}>
      {children}
    </Button>
  );
};

Object.keys(Button).forEach(item => {
  if (!['defaultProps', 'contextType'].includes(item)) {
    Index[item] = Button[item];
  }
});
Index.displayName = 'Button';
export default Index;
